﻿//2013.5.13  guxiaoli
Ext.define('HIT.view.DealSplitManualParamWin', {
    extend: 'Ext.window.Window',
    alias: 'widget.splitmanualparampanel',

    id:'split-manual-param-panel',
    height: 466,
    width: 665,
    draggable:true,
//    layout: {
//        type: 'absolute'
//    },
    title:Share.T('明细拆分'),

    initComponent: function() {
        var me = this;
         this.title = Share.T('明细拆分');  
        Ext.applyIf(me, {
        	items:[{
        		xtype:'form',
        		layout: {
        	        type: 'absolute'
        	    },
        	    height: 436,
        	    width: 665,
        		items: [
                {
                    xtype: 'fieldset',
                    x: 20,
                    y: 20,
                    height: 98,
                    width: 610,
                    title: Share.T('拆分方式'),                    
                    items: [
                        {
                            xtype: 'radiogroup',
                            layout: {
                                type: 'absolute'
                            },
                            listeners: {
                                change: RadioChange
                            },
                            id:'split-type-radio',
                            items: [
                                {
                                    xtype: 'radiofield',
                                    inputValue :'1',
                                    name:'split-type',
                                    boxLabel: Share.T('拆分单价'),
                                    x:0,
                                    y:0,
                                    checked:true
                                },
                                {
                                    xtype: 'radiofield',
                                    inputValue :'2',
                                    name:'split-type',
                                    x:150,
                                    y:0,
                                    boxLabel:Share.T('输入不含税额（单价不变）')
                                   
                                },
                                {
                                    xtype: 'radiofield',
                                    inputValue :'3',
                                    name:'split-type',
                                    x:400,
                                    y:0,
                                    id:'split-type-tax-price',
                                    boxLabel: Share.T('输入含税额（单价不变）')
                                },
                                {
                                    xtype: 'radiofield',
                                    inputValue :'4',
                                    name:'split-type',
                                    x:0,
                                    y:30,
                                    boxLabel: Share.T('拆分数量')
                                },{
                                    xtype: 'radiofield',
                                    inputValue :'5',
                                    name:'split-type',
                                    x:150,
                                    y:30,
                                    boxLabel: Share.T('输入不含税额（数量不变）')
                                },
                                {
                                    xtype: 'radiofield',
                                    inputValue :'6',
                                    name:'split-type',
                                    x:400,
                                    y:30,
                                    id:'split-type-tax-quantity',
                                    boxLabel: Share.T('输入含税额（数量不变）')
                                }
                            ]
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    x: 20,
                    y: 130,
                    height: 150,
                    width: 300,
                    title:Share.T('明细1'),
                    items: [
                        {
                            xtype: 'textfield',
                            id:'detail1-price',
                            anchor: '100%',
                            readOnly:true,
                            fieldLabel: Share.T('单价')
                        },
                        {
                            xtype: 'textfield',
                            id:'detail1-quantity',
                            anchor: '100%',
                            readOnly:true,
                            fieldLabel: Share.T('数量')
                        },
                        {
                            xtype: 'textfield',
                            id:'detail1-NTA',
                            anchor: '100%',
                            readOnly:true,
                            fieldLabel: Share.T('不含税金额')
                        },
                        {
                            xtype: 'textfield',
                            id:'detail1-TA',
                            anchor: '100%',
                            readOnly:true,
                            fieldLabel: Share.T('含税金额')
                        },
                        {
                            xtype: 'textfield',
                            id:'detail1-amount',
              //              fieldLabel: Share.T('金额'),
                            hidden:true
                        },
                        {
                            xtype: 'textfield',
                            id:'detail1-tax',
              //              fieldLabel: Share.T('税额'),
                            hidden:true
                        },
                        {
                            xtype: 'textfield',
                            id:'detail1-disamount',//明细1折扣金额
                            hidden:true
                        },
                        {
                            xtype: 'textfield',
                            id:'detail1-distax',//明细1折扣税额
                            hidden:true
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    x: 330,
                    y: 130,
                    height: 150,
                    width: 300,
                    title: Share.T('明细2'),
                    items: [
                        {
                            xtype: 'textfield',
                            id:'detail2-price',
                            anchor: '100%',
                            value:0,
                            msgTarget  : 'side',
                            regex      : /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,6})?$/,
                            regexText  : Share.T('参数输入有误'),
                            allowBlank:false,
                            blankText:Share.T('单价不能为空'),
                            fieldLabel: Share.T('单价')
                        },
                        {
                            xtype: 'textfield',
                            id:'detail2-quantity',
                            anchor: '100%',
                            value:0,
                            msgTarget  : 'side',
                            regex      : /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,6})?$/,
                            regexText  : Share.T('参数输入有误'),
                            allowBlank:false,
                            blankText:Share.T('数量不能为空'),
                            readOnly:true,
                            fieldLabel: Share.T('数量')
                        },
                        {
                            xtype: 'textfield',
                            id:'detail2-NTA',
                            anchor: '100%',
                            value:0,
                            msgTarget  : 'side',
                            regex      : /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/,
                            regexText  : Share.T('参数输入有误'),
                            allowBlank:false,
                            blankText:Share.T('不含税金额不能为空'),
                            readOnly:true,
                            fieldLabel: Share.T('不含税金额')
                        },
                        {
                            xtype: 'textfield',
                            id:'detail2-TA',
                            anchor: '100%',
                            value:0,
                            msgTarget  : 'side',
                            regex      : /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/,
                            regexText  : Share.T('参数输入有误'),
                            allowBlank:false,
                            blankText:Share.T('含税金额不能为空'),
                            readOnly:true,
                            fieldLabel: Share.T('含税金额')
                        },
                        {
                            xtype: 'textfield',
                            id:'detail2-amount',
                            fieldLabel: Share.T('金额'),
                            hidden:true
                        },
                        {
                            xtype: 'textfield',
                            id:'detail2-tax',
                            fieldLabel: Share.T('税额'),
                            hidden:true
                        },
                        {
                            xtype: 'textfield',
                            id:'detail2-disamount',//明细2折扣金额
                            hidden:true
                        },
                        {
                            xtype: 'textfield',
                            id:'detail2-distax',//明细2折扣税额
                            hidden:true
                        }
                    ]
                },
                {
                    xtype: 'fieldset',
                    x: 20,
                    y: 290,
                    height: 100,
                    width: 610,
                    layout: {
                        type: 'absolute'
                    },
                    title: Share.T('尾差'),
                    items: [
                        {
                            xtype: 'textfield',
                            x: 0,
                            y: 0,
                            width:167,
                            labelWidth:70,
                            readOnly:true,
                            id:'detail-amount',
                            fieldLabel: Share.T('不含税金额')
                        },{  //不含税金额尾差
			            	xtype: 'displayfield',
	                        x: 210,
	                        y: 0,
	                        fieldLabel: '',
	                        value: '+0.00',
	                        id:'detail-differ-amount',
	                        renderer : renderColor,
	                        width:100
			           },{
                            xtype: 'textfield',
                            x: 310,
                            y: 0,
                            labelWidth:70,
                            readOnly:true,
                            id:'detail-tax',
                            width:167,
                            fieldLabel: Share.T('税额')
                        },{  //税额尾差
			            	xtype: 'displayfield',
	                        x: 520,
	                        y: 0,
	                        fieldLabel: '',
	                        value: '+0.00',
	                        id:'detail-differ-tax',
	                        renderer : renderColor,
	                        width:100
			           },{
                            xtype: 'textfield',
                            x: 0,
                            y: 30,
                            labelWidth:70,
                            width:167,
                            readOnly:true,
                            id:'detail-disamount',
                            fieldLabel: Share.T('折扣金额')
                        },{  //不含税金额尾差
			            	xtype: 'displayfield',
	                        x: 210,
	                        y: 30,
	                        fieldLabel: '',
	                        value: '+0.00',
	                        id:'detail-differ-disamount',
	                        renderer : renderColor,
	                        width:100
			           },{
                            xtype: 'textfield',
                            x: 310,
                            y: 30,
                            width:167,
                            labelWidth:70,
                            readOnly:true,
                            id:'detail-distax',
                            fieldLabel: Share.T('折扣税额')
                        },{  //不含税金额尾差
			            	xtype: 'displayfield',
	                        x: 520,
	                        y: 30,
	                        fieldLabel: '',
	                        value: '+0.00',
	                        id:'detail-differ-distax',
	                        renderer : renderColor,
	                        width:100
			           }
                    ]
                }
            ]
          }],
           buttons:[{
          	 text:Share.T('继续拆分'),
          	 id:'split-detail-continue'
            },{
          	 text:Share.T('确定'),
          	 id:'split-detail-sure'
            },{
          	 text:Share.T('取消'),
          	 handler : function(){
                  this.up('window').close();
              }
            }]
       });

        //正负尾差颜色变化
        function renderColor(value, cellmeta, record, rowIndex, columnIndex, store) { 
        	if(value == 0){
        		return '<span style="color:#666666;">+0.00</span>';
        	}else if(value>0){
        		return "<span style='color:red;'>+" + value + "</span>";
        	}else{
        		return "<span style='color:red;'>" + value + "</span>";
        	}        	
        	
        };  
        //改变拆分方式
        function RadioChange(compo,newValue,oldValue,eOpts ){
        	var newVal = newValue['split-type'];
            if(newVal != oldValue['split-type']){
            	var leftGrid = Ext.getCmp('split-manual-left');
            	var leftSelModel = leftGrid.getSelectionModel();
            	var model = leftSelModel.getSelection()[0];
            	ResetPanelParam(model,newVal);
            }
        };

        
        me.callParent(arguments);
    }

});
